﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Assignment3.Entities
{
    class Floor : Entity
    {
        private GraphicsDevice _device;
        private Texture2D _normalMap;
            
        public Floor(Camera camera, GraphicsDevice gd, Texture2D normal) : base(camera)
        {
            _device = gd;
            _normalMap = normal;
        }

        public override void Draw()
        {
            foreach (ModelMesh mesh in Model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    part.Effect = Effects["Bump"];

                    Effects["Bump"].Parameters["World"].SetValue(ObjectWorld);
                    Effects["Bump"].Parameters["View"].SetValue(Camera.View);
                    Effects["Bump"].Parameters["Projection"].SetValue(Camera.Projection);
                    Effects["Bump"].Parameters["ColorMap"].SetValue(Texture);
                    Effects["Bump"].Parameters["NormalMap"].SetValue(_normalMap);
                    Effects["Bump"].Parameters["EyePosition"].SetValue(Camera.Position);
                    
                    Effects["Bump"].Parameters["AmbientColor"].SetValue(new Vector4(0.2f, 0.2f, 0.2f, 1f));
                    Effects["Bump"].Parameters["AmbientIntensity"].SetValue(1.5f);
                    Effects["Bump"].Parameters["LightDirection"].SetValue(new Vector3(1, 0, 0));
                    Effects["Bump"].Parameters["DiffuseColor"].SetValue(new Vector4(0.2f, 0.2f, 0.2f, 1f));
                    Effects["Bump"].Parameters["DiffuseIntensity"].SetValue(1.5f);
                    Effects["Bump"].Parameters["SpecularColor"].SetValue(new Vector4(0.3f, 0.3f, 0.3f, 1f));
                    

                    part.Effect = Effects["Basic"];

                    ((BasicEffect)Effects["Basic"]).Texture = Texture;
                    ((BasicEffect)Effects["Basic"]).TextureEnabled = true;

                    ((BasicEffect)Effects["Basic"]).World = ObjectWorld;
                    ((BasicEffect)Effects["Basic"]).View = Camera.View;
                    ((BasicEffect)Effects["Basic"]).Projection = Camera.Projection;

                    part.Effect.CurrentTechnique.Passes[0].Apply();
                }
                mesh.Draw();
            }
        }
    }
}
